<?php

class cHtmlPage extends cUiPage
/**
  DESCRIPTION
	Responsible for displaying HTML pages to the client
**/
{
	protected $msHtmlHeader;
	public $sTitle;

	function __construct(){
		parent::__construct();
		$this->AddStyle('base');
	}

	function DisplayHeader()
	/**
	  DESCRIPTION
	  	Outputs the HTML header information
	**/
	{
		global $gDycmsVersion;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!-- Powered by <?php echo($gDycmsVersion); ?> -->

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
img.icon {
	vertical-align: top;
	padding: 0;
	margin: 0;
	border: 0;
}
</style>
<title><?php echo($this->sTitle.' - '.SITE_NAME); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<!-- DyCMS CSUI Library -->
<script language="javascript" type="text/javascript" src="/private/system/public/js/mootools.js"></script>
<script language="javascript" type="text/javascript" src="/private/system/public/js/ajaxrq.js"></script>
<script language="javascript" type="text/javascript" src="/private/system/public/js/choqolate.js"></script>
<?php foreach($this->mzStyles as $id => $uri){
?><link rel="stylesheet" type="text/css" href="<?php echo $uri; ?>" id="<?php echo $id; ?>" />
<?php }; // foreach
	foreach($this->mzScripts as $id => $uri){
?><script language="javascript" type="text/javascript" src="<?php echo $uri; ?>" id="<?php echo $id; ?>"></script>
<?php }; // foreach

?><script language="javascript" type="text/javascript">
window.addEvent('domready', function(){
Choqolate.ui = new Choqolate.UI($("ui-seed"));
<?php echo(implode('\n',$this->mzStartScripts)); ?>
});
</script>
<!-- End -->

<?php foreach($this->mzMetaData as $name => $cnt){
?><meta name="<?php echo $name; ?>" content="<?php echo $cnt; ?>" />
<?php }; // foreach
	echo($this->msHtmlHeader) ?>

</head>

<body><div id="ui-seed"> </div>
<?php

	}

	function DisplayFooter()
	/**
	  DESCRIPTION
	  	Closes the HTML page
	**/
	{
?>
</body>
</html>

<!-- End DyCMS Generated Content -->
<?php
	}

	function AddHtmlHeader($s) {
		$this->msHtmlHeader .= $s;
	}
}

class cRawHtmlPage extends cUiPage
{
	function __construct(){
		parent::__construct();
		
		// Default result container
		$this->AddMetaData('resultContainer',
			dyPostOrGet('$$ui-resultContainer'));
	}
	
	function DisplayHeader(){
		$scriptCount = count($this->mzScripts);
		
		echo '<html><head>';
		
		foreach($this->mzStyles as $id => $uri){
?><link rel="stylesheet" type="text/css" href="<?php echo $uri; ?>" id="<?php echo $id; ?>" />
<?php }; // foreach
		
		// Output scripts
?><script language="javascript" type="text/javascript">
<?php	if($scriptCount > 0){
?>var scriptCount = <?php echo $scriptCount; ?>;
function onLoad(){
	if(--scriptCount == 0){
		<?php echo(implode('\n',$this->mzStartScripts)); ?>
	};
};
<?php		foreach($this->mzScripts as $id => $uri){
?>new Asset.javascript("<?php echo $uri; ?>", {id: "<?php echo $id; ?>", onload: onLoad});
<?php 		}; // foreach
		}else{
			echo(implode('\n',$this->mzStartScripts));
		};
?></script><?php

		echo '</head><body>';
		// Output meta data
		echo '<div id="Xdycms">'.json_encode($this->mzMetaData).'</div>';
	}
	
	function DisplayFooter(){
	 	echo '</body></html>';
	}
}

class cDefaultContentNode extends cDycmsClientNode
{
    function DisplayHeader(){
    }
    function DisplayFooter(){
    }
}

class cHtmlTemplate extends cDycmsClientNode
{
	protected $msName;

	function __construct($s_name)
	{
		//if(!ctype_alnum($name))
		//	throw EINVALIDARGS;

		$this->msName = "tpl-".$s_name.".php";
	}

	function DisplayBody()
	{
		global $gLocale;

		if(($fp = @fopen(ROOT.'ui/'.$this->msName, 'r', 1)) and fclose($fp))
		{
			include(ROOT.'ui/'.$this->msName);
		}
		else
		{
			include(ROOT."ui/$gLocale/sys-ui-msgnotfound.php");
			echo("uiTemplate: $this->msName, Locale: $gLocale");
		};
	}
}

class cUiPageHeader extends cHtmlWrapper
{
	protected $msInnerHtml;

	function __construct($innerHtml = '')
	{
		parent::__construct('<div class="page-header">', "</div>");

		$this->msInnerHtml = $innerHtml;
	}

	function DisplayBody()
	{
		echo $this->msInnerHtml;
	}
}

class cUiPageBody extends cHtmlWrapper
{
	protected $msInnerHtml;

	function __construct()
	{
		parent::__construct('<div class="page-body">', "</div>");
	}
}

?>
